<template>
	<p><button @click="show = true">加载异步组件</button></p>
	<AsyncComp v-if="show"/> 
</template>

<script setup>
	import { ref, defineAsyncComponent } from 'vue'
	
	import LoadingComponent from '@/components/LoadingComponent.vue'
	import ErrorComponent from '@/components/ErrorComponent.vue'
	
	const AsyncComp = defineAsyncComponent({
		//loader: () => import('@/components/MyComponent.vue'),
		loader: () => Promise.reject('加载失败'),
		loadingComponent: LoadingComponent,
		delay: 200,
		errorComponent: ErrorComponent,
		timeout: 3000
	}) 
	const show = ref(false)
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
